//var publishDate = new Date().toJSON().split('T')[0];
var publishDate = mini.formatDate(new Date(), "yyyy-MM-dd");
publishDate = '?' + publishDate;

mini.getRemoteText = function(url,params,success,error,type){
	var returnText = null;
	jQuery.ajax({
		url:url+publishDate,
		data:params,
		async:false,
		type:type?type:"get",
		cache:false,
		dataType:"text",
		success:function(text,http){
			returnText = text;
			if(success) success(text,http);
		},
		error:error
	});
	return returnText;
};
mini.getGanttRemoteText = function(url,params,success,error,type){

    var returnText = null;
    jQuery.ajax({
        url:url+publishDate,
        data:params,
        async:false,
        type:type?type:"get",
        cache:false,
        dataType:"text",
        success:function(text,http){
            returnText = text;
            if(success) success(text,http);
        },
        error:error
    });
    return returnText;
};
mini.DateParse=function(dt){
    var d = null;
    if (dt.indexOf(".") != -1) dt = dt.split(".")[0];
    if (dt.indexOf("T") != -1) d = mini.formatDate(dt, "yyyy-MM-ddTHH:mm:ss");
    else d = mini.formatDate(dt, "yyyy-MM-dd HH:mm:ss");
    return d;
	};

	mini.DateParseAndFormat=function(dt){
		if(mini.isEmpty(dt)) return '';
		var d=null;
        var f=new Date();
		var s=dt.toString();
		if(s.indexOf(".")!=-1)
			dt=s.split(".")[0];
        if (s.indexOf("T") != -1)
            d = mini.formatDate(dt, "yyyy-MM-ddTHH:mm:ss");
        else if (s.indexOf(' ') != -1)
            d = mini.formatDate(dt, "yyyy-MM-dd HH:mm:ss");
        else d = new Date(parseInt(s));
        if (d !== null)
            d = mini.formatDate(d, "yyyy-MM-dd");
		return d;


	};
	mini.FinishDateParse=function(dt)
	{
		if(mini.isEmpty(dt)) return '';
		var ds = mini.formatDate(dt,"yyyy-MM-dd 23:59:59");
		dt=new Date(ds);
		return dt;
    };
	mini.JsonDateParse = function(jsondate){
        if (jsondate === null || jsondate === '' || jsondate === undefined)
            return '';
        try {
            if (jsondate.length >= 2) return eval("new " + jsondate.substr(1, jsondate.length - 2));
        } catch (e) {}
        return '';
	};
function getCookie(sName) {
    var aCookie = document.cookie.split("; ");
    var lastMatch = null;
    for (var i = 0; i < aCookie.length; i++) {
        var aCrumb = aCookie[i].split("=");
        if (sName == aCrumb[0]) {
            lastMatch = aCrumb;
        }
    }
    if (lastMatch) {
        var v = lastMatch[1];
        if (v === undefined) return v;
        return unescape(v);
    }
    return null;
}

function onFormReset() {
    onFormAction("cancel");
}

function onFormClose() {
    onFormAction("close");
}

function onFormAction(action) {
    if (window.CloseOwnerWindow)
        return window.CloseOwnerWindow(action);
    else window.close();
}

function onFormSave(form,url,data,type) {
    onCallFormSave(form,url,data,type?type:'get',null);
}
function onCallFormSave(form,url,data,type,fn,scope) {
    form.validate();
    if (form.isValid() === false)
        return;

    form.loading();
    $.ajax({
        url: url,
        data: data,
        type:type?type:"get",
        cache: false,
        success: function (text) {
            if(!fn)
                onFormAction("save");
            else{
                fn.call(scope || this);
            }
            form.unmask();
        },
        error: function (jqXHR, textStatus, errorThrown) {
            form.unmask();
            mini.alert(jqXHR.responseText,'警告');
            if(scope) scope.fire('formSaveException');
        }
    });
}

mini.isEmpty = function(dt) {
    if (dt === undefined || dt === null || dt === '')
        return true;
    return false;
};
mini.GetParas = function getParameter(sProp) {
    var re = new RegExp(sProp + "=([^\&]*)", "i");
    var a = re.exec(document.location.search);
    if (a === null)
        return null;
    return a[1];
};
///获取顶层的PATH
mini.getTopPATH = function () {
    var $ = [];
    function topWin(A) {
        try {
            if (A.mini)
                $.push(A);
            if (A.parent && A.parent != A)
                topWin(A.parent)
        } catch (e) { }
    }
    topWin(window);
    var win = $[$.length - 1];
    var href = '';
    try {
        href = win.document.referrer;
    } catch (e) {
        href = win.document.referrer;
    }
    var path = href.split('/');
    var topPATH = path[0] + '/' + path[1] + '/' + path[2] + '/';
    return topPATH;
};
mini.OpenUrlInTab= function(title,url)
{
    ///======= 创建iframe ===========================
    var iframe = document.createElement("iframe");
    iframe.setAttribute("id", "iframeId");
    iframe.setAttribute("name", "iframeName");
    iframe.style.display = "none";
    document.body.appendChild(iframe);

    ///======= 创建Form =============================
    var form = document.createElement("form");
    form.setAttribute("method", "post");
    ///iframe的name与form的target名称必须相同
    form.setAttribute("target", "iframeName");

    form.setAttribute("action", mini.getTopPATH() + "deputyPage");
    ///==== 创建隐藏表单 ============================
    //title
    var titleField = document.createElement("input");
    titleField.setAttribute("name", "title");
    titleField.setAttribute("value", title);
    titleField.setAttribute("type", "hidden");
    form.appendChild(titleField);
    //url
    var urlField = document.createElement("input");
    urlField.setAttribute("name", "url");
    urlField.setAttribute("value", url);
    urlField.setAttribute("type", "hidden");
    form.appendChild(urlField);
    document.body.appendChild(form);
    ////===== Form提交 ==============================
    form.submit();
    ////===== 删除Form ==============================
    document.body.removeChild(form);
};
///成功后释放iframe,form
function removeIframe(iframe, form) {
    ////===== 删除Form ==============================
    document.body.removeChild(form);
    ////===== 删除iframe ============================
    //指向空白页
    //iframe.src="about:blank";
    try {
        iframe.contentWindow.document.write("");
        iframe.contentWindow.document.clear();
        iframe.contentWindow.close();
        document.body.removeChild(iframe);
    } catch (e) {
        iframe.parentNode.removeChild(iframe);
    }
}

mini.CloseCurrentTab= function()
{
    var topWin = window.top;
    topWin.GNC.Web.App.mainTab.closeCurrentTab();
};